<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd">

<sqlMap namespace="${domain}">
	<typeAlias alias="${domainVarName}" type="${packageName}.${domain}"/>

	<resultMap id="result" class="${domainVarName}">
		<#list fieldMappers as fieldMapper>
		<result property="${fieldMapper.fieldName}" column="${fieldMapper.column.columnName}" />
		</#list>
	</resultMap>

	<insert id="insert" parameterClass="${domainVarName}">
		INSERT INTO ${tableName} (<#list fieldMappers as fieldMapper>${fieldMapper.column.columnName}<#if fieldMapper_has_next>, </#if></#list>) 
		VALUES(<#list fieldMappers as fieldMapper>#${fieldMapper.fieldName}#<#if fieldMapper_has_next>, </#if></#list>)
		<selectKey resultClass="int">SELECT @@IDENTITY</selectKey>
	</insert>
	
	<update id="update" parameterClass="${domainVarName}">
		UPDATE ${tableName} SET <#list fieldMappers as fieldMapper>${fieldMapper.column.columnName}=#${fieldMapper.fieldName}#<#if fieldMapper_has_next>, </#if></#list>
		WHERE <#list primaryKeyMappers as primaryKeyMapper>${primaryKeyMapper.column.columnName}=#${primaryKeyMapper.fieldName}#<#if primaryKeyMapper_has_next> AND </#if></#list>
	</update>
	
	<select id="select" parameterClass="int" resultMap="result">
		SELECT <#list fieldMappers as fieldMapper>${fieldMapper.column.columnName}<#if fieldMapper_has_next>, </#if></#list> 
		FROM ${tableName} 
		WHERE <#list primaryKeyMappers as primaryKeyMapper>${primaryKeyMapper.column.columnName}=#${primaryKeyMapper.fieldName}#<#if primaryKeyMapper_has_next> AND </#if></#list>
	</select>
	
	<select id="selectList" parameterClass="searchCondition" resultMap="result">
		SELECT <#list fieldMappers as fieldMapper>${fieldMapper.column.columnName}<#if fieldMapper_has_next>, </#if></#list> 
		FROM ${tableName}
	</select>
</sqlMap>